package org.gingresosapi.persistencia;

import org.gingresosapi.beans.Regimencomercios;
import java.sql.Date; 
import org.gingresosapi.beans.*;
import org.gingresosapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.gingresosapi.generales.Mensajeria;
import org.gingresosapi.generales.DataGManager;


/**
*
* @author
*/

public class RegimencomerciosPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/gingresosapi/properties/mensajes");
static DataGManager dataGManager;
static List<Regimencomercios> list;

public RegimencomerciosPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Regimencomercios regimencomercios ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into regimencomercios(idcomercio,idregimen,valor,periodopago,mespago,fechainscripcion,idusuario,fecha,activo,idmunicipio)  values(?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setString(1,regimencomercios.getIdcomercio());
        pinsert.setString(2,regimencomercios.getIdregimen());
        pinsert.setDouble(3,regimencomercios.getValor());
        pinsert.setString(4,regimencomercios.getPeriodopago());
        pinsert.setString(5,regimencomercios.getMespago());
        pinsert.setDate(6,regimencomercios.getFechainscripcion());
        pinsert.setString(7,regimencomercios.getIdusuario());
        pinsert.setDate(8,regimencomercios.getFecha());
        pinsert.setString(9,regimencomercios.getActivo());
        pinsert.setString(10,regimencomercios.getIdmunicipio());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Regimencomercios regimencomercios ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update regimencomercios set  idcomercio=?, idregimen=?, valor=?, periodopago=?, mespago=?, fechainscripcion=?, idusuario=?, fecha=?, activo=?, idmunicipio=?  where  idcomercio ='"+regimencomercios.getIdcomercio()+"' and  idregimen ='"+regimencomercios.getIdregimen()+"' and  activo ='"+regimencomercios.getActivo()+"' and  idmunicipio ='"+regimencomercios.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,regimencomercios.getIdcomercio());
pupdate.setString(2,regimencomercios.getIdregimen());
pupdate.setDouble(3,regimencomercios.getValor());
pupdate.setString(4,regimencomercios.getPeriodopago());
pupdate.setString(5,regimencomercios.getMespago());
pupdate.setDate(6,regimencomercios.getFechainscripcion());
pupdate.setString(7,regimencomercios.getIdusuario());
pupdate.setDate(8,regimencomercios.getFecha());
pupdate.setString(9,regimencomercios.getActivo());
pupdate.setString(10,regimencomercios.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  regimencomercios set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Regimencomercios regimencomercios_old , Regimencomercios regimencomercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update regimencomercios set  idcomercio=? ,  idregimen=? ,  activo=? ,  idmunicipio=?  where  idcomercio ='"+regimencomercios_old.getIdcomercio()+"' and  idregimen ='"+regimencomercios_old.getIdregimen()+"' and  activo ='"+regimencomercios_old.getActivo()+"' and  idmunicipio ='"+regimencomercios_old.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,regimencomercios.getIdcomercio());pupdate.setString(2,regimencomercios.getIdregimen());pupdate.setString(9,regimencomercios.getActivo());pupdate.setString(10,regimencomercios.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Regimencomercios regimencomercios ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimencomercios  where  idcomercio = ? and  idregimen = ? and  activo = ? and  idmunicipio = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setString(1,regimencomercios.getIdcomercio());
pdelete.setString(2,regimencomercios.getIdregimen());
pdelete.setString(9,regimencomercios.getActivo());
pdelete.setString(10,regimencomercios.getIdmunicipio());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimencomercios where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimencomercios  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Regimencomercios regimencomercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from regimencomercios where idcomercio='"+regimencomercios.getIdcomercio()+"' and idregimen='"+regimencomercios.getIdregimen()+"' and activo='"+regimencomercios.getActivo()+"' and idmunicipio='"+regimencomercios.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Regimencomercios findByPrimaryKey(Regimencomercios regimencomercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from regimencomercios where idcomercio='"+regimencomercios.getIdcomercio()+"' and idregimen='"+regimencomercios.getIdregimen()+"' and activo='"+regimencomercios.getActivo()+"' and idmunicipio='"+regimencomercios.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            regimencomercios.setIdcomercio(rs.getString("idcomercio"));
regimencomercios.setIdregimen(rs.getString("idregimen"));
regimencomercios.setValor(rs.getDouble("valor"));
regimencomercios.setPeriodopago(rs.getString("periodopago"));
regimencomercios.setMespago(rs.getString("mespago"));
regimencomercios.setFechainscripcion(rs.getDate("fechainscripcion"));
regimencomercios.setIdusuario(rs.getString("idusuario"));
regimencomercios.setFecha(rs.getDate("fecha"));
regimencomercios.setActivo(rs.getString("activo"));
regimencomercios.setIdmunicipio(rs.getString("idmunicipio"));
    }
    rs.close();
    psquery.close();
 return regimencomercios;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdcomercio()
*/

public static List<Regimencomercios> findByIdcomercio(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where idcomercio='"+regimencomercios.getIdcomercio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdregimen()
*/

public static List<Regimencomercios> findByIdregimen(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where idregimen='"+regimencomercios.getIdregimen()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByValor()
*/

public static List<Regimencomercios> findByValor(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where valor='"+regimencomercios.getValor()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPeriodopago()
*/

public static List<Regimencomercios> findByPeriodopago(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where periodopago='"+regimencomercios.getPeriodopago()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByMespago()
*/

public static List<Regimencomercios> findByMespago(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where mespago='"+regimencomercios.getMespago()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFechainscripcion()
*/

public static List<Regimencomercios> findByFechainscripcion(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where fechainscripcion='"+regimencomercios.getFechainscripcion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdusuario()
*/

public static List<Regimencomercios> findByIdusuario(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where idusuario='"+regimencomercios.getIdusuario()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFecha()
*/

public static List<Regimencomercios> findByFecha(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where fecha='"+regimencomercios.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByActivo()
*/

public static List<Regimencomercios> findByActivo(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where activo='"+regimencomercios.getActivo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Regimencomercios> findByIdmunicipio(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where idmunicipio='"+regimencomercios.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Regimencomercios> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
  String sql = "select * from regimencomercios";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from regimencomercios";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from regimencomercios where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from regimencomercios";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from regimencomercios where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Regimencomercios> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Regimencomercios>();
  String sql = "select * from regimencomercios where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Regimencomercios> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Regimencomercios>();
  String sql = "select * from regimencomercios";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("idcomercio"),rs.getString("idregimen"),rs.getDouble("valor"),rs.getString("periodopago"),rs.getString("mespago"),rs.getDate("fechainscripcion"),rs.getString("idusuario"),rs.getDate("fecha"),rs.getString("activo"),rs.getString("idmunicipio"));
            
            
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
